<template>
  <div class="AllName">
    <div
      class="center"
      v-infinite-scroll="load"
      infinite-scroll-disabled="disabled"
    >
      <div class="box" v-for="item in records" :key="item.id">
        <img class="img" :src="ip + item.imgUrl" alt="" />
        <p class="time">{{ item.createTime }}</p>
        <p class="name">{{ item.userName }}</p>
        <p class="job">{{ item.job }}</p>
      </div>

      <div class="box1">
        <img @click="gotoWrite()" src="../assets/images/jiahao.png" alt="" />
      </div>
    </div>
  </div>
</template>

<script>
import { GetAllName, GetIP } from "../api/index";
export default {
  name: "AllName",
  data() {
    return {
      now: 1, //页数
      size: 10, //每页的数据量
      records: [],
      ip: GetIP,
      pages: 0, //总共页数
      current: 1, //第几页
      loading: false, //是否加载
    };
  },
  computed: {
    // 判断有无数据
    noMore() {
      return (
        document.documentElement.scrollTop + window.screen.height >=
          document.body.clientHeight && this.current >= this.pages
      );
    },
    // 是否加载
    disabled() {
      return this.loading || this.noMore;
    },
  },
  created() {
    this.getAllShowName();
  },
  methods: {
    // 获取数据
    getAllShowName() {
      GetAllName({
        now: this.now,
        size: this.size,
      }).then((res) => {
        if (res.status == 200) {
          this.records = this.records.concat(res.data.data.records);
          this.pages = res.data.data.pages;
          this.current = res.data.data.current;
          this.loading = false;
        } else {
          this.$message.error("没有数据");
        }
      });
    },
    
    // 前往个人主页
    gotoWrite() {
      this.$router.push("/writer");
    },

    // 加载数据
    load() {
      this.loading = true;
      setTimeout(() => {
        this.now += 1;
        this.getAllShowName();
      }, 2000);
    },
  },
};
</script>

<style scoped>
.AllName {
  background-color: #eb7072;
  width: 100%;
  height: 100%;
}

.center {
  margin: 0 auto;
  width: 1400px;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-start;
  align-items: flex-start;
  height: 821px;
  overflow: auto;
}
.box {
  width: 300px;
  height: 400px;
  background-color: white;
  border-radius: 5%;
  margin-top: 100px;
  margin-right: 25px;
}
.img {
  width: 280px;
  height: 220px;
  margin: 10px;
  text-align: center;
  border-radius: 5%;
}
.time {
  margin-left: 10px;
  margin-right: 10px;
  color: #eb7072;
}
.name {
  margin-left: 10px;
  margin-right: 10px;
  color: #eb7072;
}
.job {
  margin-left: 10px;
  margin-right: 10px;
  color: #eb7072;
}
.box1 {
  width: 300px;
  height: 400px;
  background-color: rgba(255, 255, 255, 0.685);
  margin-top: 100px;
  border-radius: 5%;
  opacity: 0.8;
}
.box1 img {
  display: block;
  margin: 0 auto;
  width: 25%;
  height: 22%;
  text-align: center;
  margin-top: 156px;
  cursor: pointer;
}
</style>